import React from 'react';
import {Router, Route, Switch, Redirect } from 'dva/router';
import dynamic from 'dva/dynamic';

function RouterConfig({history, app}) {
  const routes = [
    { path: '/main', app, component: () => import('./routes/Main'),  },
    { path: '/login',app,component: () => import('./routes/Login'),  },
    { path: '/resourceManager',app,component: () => import('./routes/system/ResourceManager'),
      models: () => [
        import('./models/system/resourceManager'),
      ],},
    { path: '/role',app,component: () => import('./routes/system/Role'),
      models: () => [
        import('./models/system/role'),
      ],},
    { path: '/admin',app,component: () => import('./routes/system/Admin'),
      models: () => [
        import('./models/system/admin'),
      ],},
    { path: '/files',app,component: () => import('./routes/system/File'),
      models: () => [
        import('./models/system/file'),
      ], },
    { path: '/merchant',app,component: () => import('./routes/shop/Merchant'),
      models: () => [
        import('./models/shop/merchant'),
      ],},
    { path: '/myMerchant',app,component: () => import('./routes/shop/MyMerchant'),
      models: () => [
        import('./models/shop/merchant'),
      ],},
    { path: '/customerType',app,component: () => import('./routes/system/CustomerType'), models: () => [
      import('./models/system/customerType'),
    ], },
    { path: '/customer',app,component: () => import('./routes/shop/Customer'), models: () => [
      import('./models/shop/customer'),
    ], },
    { path: '/charge',app,component: () => import('./routes/shop/Charge'), models: () => [
      import('./models/shop/charge'),
    ], },
    { path: '/customerPay',app,component: () => import('./routes/shop/CustomerPay'), models: () => [
      import('./models/shop/charge'),
    ], },
    { path: '/customerPayRecords',app,component: () => import('./routes/finance/CustomerPayRecord') , models: () => [
      import('./models/finance/finance'),
    ],    },
    { path: '/inOutDayRecord',app,component: () => import('./routes/finance/InOutDayRecord'), models: () => [
      import('./models/finance/finance'),
    ], },
    { path: '/serviceDayMoney',app,component: () => import('./routes/finance/ServiceDayMoney'), models: () => [
    import('./models/finance/finance'),
  ], },
    { path: '/dashBoard',app,component: () => import('./routes/finance/DashBoard'), models: () => [
      import('./models/finance/finance'),
    ], },
  ];

  return (
    <Router history={history}>
      <Switch>
        <Route exact path="/" render={()=>(<Redirect to="/login" />)}/>
        {
          routes.map(({path, ...param}, key) => (
            <Route key={key} exact path={path} component={dynamic({...param})}></Route>
          ))
        }
      </Switch>
    </Router>
  );
}

export default RouterConfig;
